package it.sd.pwframework.admin.bean;

import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedProperty;
import javax.faces.context.FacesContext;

import org.primefaces.context.RequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class AbstractJsfBean implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@ManagedProperty(value="#{sessionBean}")
    protected SessionBean sessionBean= null;

    protected Logger log = LoggerFactory.getLogger(this.getClass());
	
	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	protected void showErrorMessage(String message1) {
		showMessage(FacesMessage.SEVERITY_ERROR, message1, null);
	}

	protected void showInfoMessage(String message1) {
		showMessage(FacesMessage.SEVERITY_INFO, message1, null);

	}

	protected void showErrorMessage(String message1, Throwable t) {
		log.error(message1, t );
		showMessage(FacesMessage.SEVERITY_ERROR,message1, t.getLocalizedMessage());
	}

	protected void showErrorMessage(String message1, String message2) {
		showMessage(FacesMessage.SEVERITY_ERROR, message1, message2);
	}

	protected void showInfoMessage(String message1, String message2) {
		showMessage(FacesMessage.SEVERITY_INFO, message1, message2);

	}

	protected void showMessage(FacesMessage.Severity severity, String message1,
			String message2) {
		FacesMessage message = new FacesMessage(severity, message1, message2);
		FacesContext.getCurrentInstance().addMessage(null, message);
	}
	
	public SessionBean getSessionBean() {
		return sessionBean;
	}

	public void setSessionBean(SessionBean sessionBean) {
		this.sessionBean = sessionBean;
	}
	

	protected void addCallBackOk() {
        RequestContext.getCurrentInstance().addCallbackParam("saved", "OK");
	}
	
	
}
